<form class="layui-form layui-form-pane" id="suFormPwd">
    <div class="layui-form-item">
        <label class="layui-form-label red-star-label">原密码:</label>
        <div class="layui-input-block">
            <input type="password" name="oldPassword" placeholder="请输入原始密码" class="layui-input"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label red-star-label">新密码:</label>
        <div class="layui-input-block">
            <input type="password" name="newPassword" placeholder="请输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label red-star-label">确认密码:</label>
        <div class="layui-input-block">
            <input type="password" name="rePassword" placeholder="请再次输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|rePassword" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block text-right">
            <button class="layui-btn" lay-filter="suFormSubmitPwd" lay-submit style="width: 150px">保存</button>
        </div>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'reqApi', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var reqApi = layui.reqApi;
        var admin = layui.admin;

        // 添加表单验证方法
        form.verify({
            rePassword: function (t) {
                if (t !== $('#suFormPwd input[name=newPassword]').val()) {
                    return '两次密码输入不一致';
                }
            }
        });

        // 监听提交
        form.on('submit(suFormSubmitPwd)', function (obj) {
            var reqEL = layer.msg('操作执行中', {icon: 16, shade: 0.01, time: 6000});
            admin.req({
                url: reqApi.admin.home.updatePassword
                , type: 'put'
                , data: obj.field
                , complete: function () {
                    layer.close(reqEL);
                }
                , success: function () {
                    layer.closeAll();
                    layer.msg('操作成功', {offset: '15px', icon: 1, time: 500});
                }
            });
            return false;
        });
    });
</script>